package ar.edu.itba.it.paw.web.component;

import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;

import ar.edu.itba.it.paw.domain.Auction;
import ar.edu.itba.it.paw.domain.Product;

public class TypeLabel extends Label{
	
	

	public TypeLabel(String id, IModel<Product> model) {
		super(id, new ProductTypeModel(model));
		
		Product product = model.getObject();

		if(product.getClass() == Auction.class &&  ((Auction)product).isEnded()){
			add(new SimpleAttributeModifier("style", "color: #00FF00"));
			return;
		}
		if(product.getClass() == Product.class && product.getQuantity() == 0){
			add(new SimpleAttributeModifier("style", "color: #0000FF"));
			return;
		}
		add(new SimpleAttributeModifier("style", "color: #FF0000"));
		return;
	}
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static final class ProductTypeModel extends AbstractReadOnlyModel<String> {

		private IModel<Product> product;

		public ProductTypeModel(IModel<Product> product) {
			this.product = product;
		}

		@Override
		public String getObject() {
			return product.getObject() instanceof Auction ? "SUBASTA" : "PRODUCTO";
		}

	}
	
}
